package cn.ffcs.uec.outStaff.component;

import lombok.Getter;
import lombok.Setter;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.Div;
import org.zkoss.zul.ListModel;

import cn.ffcs.uec.outStaff.component.bean.UecOutStaffAndContractListboxBean;
import cn.ffcs.uec.outStaff.constant.UecOutStaffConstants;
import cn.ffcs.uec.outStaff.manager.UecOutStaffContractManager;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.vo.PageInfo;

@Controller
@Scope("prototype")
public class UecOutStaffAndContractListboxExt extends Div implements IdSpace {
	private static final long serialVersionUID = -6295283038198818335L;
	
	/**
	 * 对应页面上的bean
	 */
	private UecOutStaffAndContractListboxBean bean = new UecOutStaffAndContractListboxBean();

	private UecOutStaffContractManager uecOutStaffContractManager = (UecOutStaffContractManager) ApplicationContextUtil
			.getBean("uecOutStaffContractManager");

	@Getter
	@Setter
	private IPortletInfoProvider portletInfoProvider;

	public UecOutStaffAndContractListboxExt() {
		Executions.createComponents(
				UecOutStaffConstants.UEC_OUT_STAFFCONTRACT_EXT_LISTBOX_ZUL,
				this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');
	}

	/**
	 * 初始化
	 */
	public void onCreate() {
		onQueryUecOutStaffContractList();
	}

	/**
	 * 翻页
	 */
	public void onUecOutStaffContractListboxPaging() {
		this.onQueryUecOutStaffContractList();
	}

	/**
	 * 查询
	 */
	public void onQueryUecOutStaffContractList() {
		PageInfo pageInfo = uecOutStaffContractManager
				.queryPageInfo(
						this.bean.getUecOutStaffContractListboxPaging()
								.getActivePage() + 1, this.bean
								.getUecOutStaffContractListboxPaging()
								.getPageSize());
		ListModel list = new BindingListModelList(pageInfo.getDataList(), true);
		this.bean.getUecOutStaffContractListbox().setModel(list);
		this.bean.getUecOutStaffContractListboxPaging().setTotalSize(
				pageInfo.getTotalCount());

	}
}
